package com.zf.admin.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zf.admin.pojo.Userlist;
import com.zf.admin.service.UserlistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class UserlistController {

    @Autowired
    private UserlistService userlistService;


    @RequestMapping("/findalluserlist")
    public String findalluserlist(Model model, @RequestParam(required = false, defaultValue = "1") Integer page,
                                  @RequestParam(required = false, defaultValue = "2") Integer pageSize) {
        PageHelper.startPage(page, pageSize);
        List<Userlist> userlist = userlistService.findalluserlist();
        PageInfo<Userlist> p = new PageInfo<Userlist>(userlist);
        model.addAttribute("userlist", userlist);
        model.addAttribute("p", p);
        model.addAttribute("mainPage", "userlist.jsp");
        return "admin/main1";
    }

    //删除用户信息
    @RequestMapping("/deleteuserlist")
    public String deleteuserlist(Model model, Integer id) {
        userlistService.deleteuserlist(id);
        model.addAttribute("error", "deletesuccess");
        return "redirect:findalluserlist";
    }
}
